package com._23DesignPattern._create.Singleton;

/**
 * @Author: huangya
 * @Date: 2018/10/19
 * @Description: 懒汉
 *
 */
public class SingletonDemo {

    private static SingletonDemo singletonDemo = null;

    private SingletonDemo() {
    }

    public static SingletonDemo getInstance(){
        if(singletonDemo==null){
            singletonDemo = new SingletonDemo();
        }
        return singletonDemo;
    }


    public synchronized static SingletonDemo getInstance1(){
        if(singletonDemo==null){
            singletonDemo = new SingletonDemo();
        }
        return singletonDemo;
    }

    public static SingletonDemo getInstance2(){
        if (singletonDemo == null) {
            synchronized (SingletonDemo.class){
                if (singletonDemo == null) {
                    singletonDemo = new SingletonDemo();
                }
            }
        }
        return singletonDemo;
    }

}
